/******************************************************************************/
/*                                                                            */
/*  File: xhelper.h                                                           */
/*  Author: bkenwright@xbdev.net                                              */
/*  URL: www.xbdev.net                                                        */
/*                                                                            */
/******************************************************************************/
/*

*/
/******************************************************************************/

#pragma once


#include "..\physics\collision.h"
#include "xtxtloader.h"


inline void XMeshMinMax(const stXFrame* xFrame, const stXMesh* xMesh, D3DXVECTOR3* vmin, D3DXVECTOR3* vmax)
{
	if (xMesh->m_numVerts==0 || xMesh->m_numTris==0) return;

	const int numVerts	= xMesh->m_numVerts;
	const int numTris	= xMesh->m_numTris;

	D3DXVECTOR3 vertTrans;
	for (int i=0; i<numVerts; i++)
	{
		D3DXVec3TransformCoord(	&vertTrans, &xMesh->m_verts[i], &xFrame->m_matAnim);
		vmin->x = min(vmin->x, vertTrans.x);
		vmin->y = min(vmin->y, vertTrans.y);
		vmin->z = min(vmin->z, vertTrans.z);

		vmax->x = max(vmax->x, vertTrans.x);
		vmax->y = max(vmax->y, vertTrans.y);
		vmax->z = max(vmax->z, vertTrans.z);
	}
}


inline void XFrameMinMax(const stXFrame* xFrame, D3DXVECTOR3* vmin, D3DXVECTOR3* vmax)
{
	DBG_ASSERT(xFrame);
	DBG_ASSERT(xFrame->GetType()==X_FRAME);


	while (xFrame)
	{
		if (xFrame->m_child)
		{
			DBG_ASSERT(xFrame!=xFrame->m_child);
			XFrameMinMax(xFrame->m_child, vmin, vmax);
		}

		stXMesh* xMesh = xFrame->m_mesh;
		while (xMesh)
		{
			XMeshMinMax(xFrame, xMesh, vmin, vmax);
			xMesh = xMesh->m_next;
		}

		xFrame = xFrame->m_next;
	}

}


/******************************************************************************/

void XMeshCollisionTest(const stXFrame* xFrame, const stXMesh* xMesh, stCollisionInfo* collisionInfo);

/******************************************************************************/

void XFrameCollisionTest(const stXFrame* xFrame, stCollisionInfo* collisionInfo);

/******************************************************************************/




